﻿Imports System.Reflection
Imports System.Xml

Public Class TrackDataReader
    Private _xml_doc As New System.Xml.XmlDocument
    Private _Tracks As Tracks
    Private _CurrentTrack As Track
    Public Enum TrackVisability
        [Public]
        [Private]
    End Enum
    Public Sub New(ByVal XmlDate As String)
        _xml_doc.LoadXml(XmlDate)
    End Sub
    Public Sub ReadData(ByRef o_Tracks As Tracks)
        Dim TNodeList As XmlNodeList = _xml_doc.GetElementsByTagName("track")
        Dim o_Track As Track
        For Each TNode As System.Xml.XmlNode In TNodeList
            'add the track
            o_Track = New Track
            With o_Track
                .Id = XmlTools.GetXmlSingle(TNode, "id")
                .Isrc = XmlTools.GetXmlString(TNode, "isrc")
                .Permalink = XmlTools.GetXmlString(TNode, "permalink")
                .Permalinkurl = XmlTools.GetXmlString(TNode, "permalink-url")
                .Playbackcount = XmlTools.GetXmlSingle(TNode, "playback-count")
                .Purchaseurl = XmlTools.GetXmlString(TNode, "purchase-url")
                .Release = XmlTools.GetXmlString(TNode, "release")
                .Releaseday = XmlTools.GetXmlSingle(TNode, "release-day")
                .Releasemonth = XmlTools.GetXmlSingle(TNode, "release-month")
                .Releaseyear = XmlTools.GetXmlSingle(TNode, "release-year")
                .Sharing = XmlTools.GetXmlPublicPrivate(TNode, "sharing")
                .Streamable = XmlTools.GetXmlBooloean(TNode, "streamable")
                .Streamurl = XmlTools.GetXmlString(TNode, "stream-url")
                .Title = XmlTools.GetXmlString(TNode, "title")
                .Uri = XmlTools.GetXmlString(TNode, "uri")
                .user = XmlTools.ReadUser(TNode.Item("user"))
                .Userid = XmlTools.GetXmlSingle(TNode, "user-id")
                .Waveformurl = XmlTools.GetXmlString(TNode, "waveform-url")
                .Description = XmlTools.GetXmlString(TNode, "description")
                .Genre = XmlTools.GetXmlString(TNode, "genre")
                .Downloadcount = XmlTools.GetXmlSingle(TNode, "download-count")
                .Commentcount = XmlTools.GetXmlSingle(TNode, "comment-count")
                .Artworkurl = XmlTools.GetXmlString(TNode, "artwork-url")
                .Downloadurl = XmlTools.GetXmlString(TNode, "download-url")
                .Bpm = XmlTools.GetXmlString(TNode, "bpm")
                .Createdate = XmlTools.GetXmlDate(TNode, "created-at")
                .Downloadable = XmlTools.GetXmlBooloean(TNode, "downloadable")
                .Duration = XmlTools.GetXmlSingle(TNode, "duration")
            End With
            o_Tracks.Add(o_Track)
        Next
    End Sub
    
End Class
